package StudyCode.summary.zipfile;

import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class FindFileInZipFile {
	public static void main(String args[]) {
		try {
			ZipFile sourceZipFile = new ZipFile("E:/Copy/zipdemo.zip");
			String searchFileName = "csv.csv";
			Enumeration e = sourceZipFile.entries();
			boolean found = false;

			System.out.println("开始搜索查找文件 " + searchFileName + " 在zip文件 " + sourceZipFile.getName());

			while (e.hasMoreElements()) {
				ZipEntry entry = (ZipEntry) e.nextElement();

				if (entry.getName().toLowerCase().contains(searchFileName)) {
					found = true;
					System.out.println("找到 " + entry.getName());
				}
			}

			if (!found) {
				System.out.println("文件 :" + searchFileName + " 未找到在zip文件: " + sourceZipFile.getName());
			}
			sourceZipFile.close();

		} catch (IOException ioe) {
			ioe.printStackTrace();
		}
	}
}
